package com.myhexin.demo.ignite.test.base;

import org.apache.ignite.IgniteBinary;
import org.apache.ignite.Ignition;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.client.ClientCache;
import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.configuration.ClientConfiguration;

public class BinaryDemo {

    private static final String IGNITE_ADDR = "127.0.0.1:10800";

    public static void main(String[] args) {
        ClientConfiguration cfg = new ClientConfiguration();
        cfg.setAddresses(IGNITE_ADDR);
        try (IgniteClient client = Ignition.startClient(cfg)) {
            // 写入数据
            IgniteBinary binary = client.binary();
            BinaryObject val = binary.builder("Person")
                    .setField("id", 2, int.class)
                    .setField("name", "Joe", String.class)
                    .build();
            ClientCache<Integer, BinaryObject> cache = client.getOrCreateCache("personCache").withKeepBinary();
            cache.put(2, val);
            // 查询数据
            BinaryObject value = cache.get(2);
            System.out.println(value);
        }
    }
}
